<template>
  <el-form-item>
    <el-input maxlength="9" placeholder="最低进货价" v-model="price_low" @change="priceChanged()" clearable style="width:110px;">
    </el-input>
    <span style="color:rgb(181,180,180)">-</span>
    <el-input maxlength="9" placeholder="最高进货价" v-model="price_high" @change="priceChanged()" clearable style="width:110px;">
    </el-input>
  </el-form-item>
</template>
<script>
export default {
  name: 'DjGiftPriceSelect',
  props: {
    data: {
      type: Object,
      default() {
        return {};
      }
    },
    from: {
      type: Number,
      default: 0
      // 1：供应商，2：中央仓
    },
    usedfor: {
      type: Number,
      default: 0
      // 1:运管系统采购下单，2：采购平台总部下单，3：采购平台总部统配
    }
  },
  data() {
    return {
      price_low: '',
      price_high: ''
    };
  },
  watch: {
    price_low(v) {
      let str = String(v);
      if (/^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$/g.test(str)) {
        this.price_low = str;
      } else {
        this.price_low = str.substring(0, str.length - 1);
      }
    },
    price_high(v) {
      let str = String(v);
      if (/^(([1-9]{1}\d*)|(0{1}))(\.\d{0,2})?$/g.test(str)) {
        this.price_high = str;
      } else {
        this.price_high = str.substring(0, str.length - 1);
      }
    }
  },
  methods: {
    priceChanged() {
      let val = {
        price_low: this.price_low,
        price_high: this.price_high
      };
      this.$emit('change', val);
    }
  }
};
</script>